package com.feige.common.ex;

import com.feige.common.enums.ResponseEnum;
import lombok.Data;

@Data
public class BussinessException extends RuntimeException {
    private Integer code;

    /**
     * 接受状态码和消息
     *
     * @param code
     * @param message
     */
    public BussinessException(Integer code, String message) {
        super(message);
        this.code = code;
    }

    /**
     * 接收枚举类型
     *
     * @param resultCodeEnum
     */
    public BussinessException(ResponseEnum resultCodeEnum) {
        super(resultCodeEnum.getMsg());
        this.code = resultCodeEnum.getCode();
    }

    /**
     * 如果满足条件，抛出异常
     *
     * @param condition      条件
     * @param resultCodeEnum 类型
     */
    public static void throwMatch(boolean condition, ResponseEnum resultCodeEnum) {
        if (condition) {
            throw new BussinessException(resultCodeEnum);
        }
    }
}